//
//  BYHomeViewController.m
//  BYControls
//
//  Created by 彬boy on 2018/11/14.
//  Copyright © 2018年 彬boy. All rights reserved.
//

#import "BYHomeViewController.h"
#import "BYHomeSeleViewController.h"
#import "BYNavSearchBar.h"
#import "BYSearchViewController.h"

@interface BYHomeViewController ()<UISearchBarDelegate>

@property (nonatomic, strong) BYNavSearchBar *ohSearchBar;

@end

@implementation BYHomeViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.by_navBarControl.backgroundColor = [UIColor redColor];
    
    UIImageView *leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scan"]];
    leftView.bounds = CGRectMake(0, 0, 24, 24);
    self.ohSearchBar = [[BYNavSearchBar alloc] initWithFrame:CGRectMake(10*kXX, 4, kScreenW-80*kXX, 36) placeholder:@"点击跳转" textFieldLeftView:leftView showCancleBtn:NO tintColor:[UIColor clearColor]];
    self.by_navBarControl.navTitleView = self.ohSearchBar;
    self.ohSearchBar.delegate = self;
    
    UIButton *messageButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [messageButton setImage:[UIImage imageNamed:@"scan"] forState:UIControlStateNormal];
    messageButton.frame = CGRectMake(kScreenW-50*kXX, 2, 40, 40);
    [messageButton addTarget:self action:@selector(messageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.by_navBarControl.navRightBtn = messageButton;
}



- (void)messageBtnClick:(UIButton *)sender {
    
    BYHomeSeleViewController *bySeleVC = [[BYHomeSeleViewController alloc] init];
    [self.navigationController pushViewController:bySeleVC animated:YES];
}


- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
    BYSearchViewController *ohSearchViewController = [[BYSearchViewController alloc] init];
    [self.navigationController pushViewController:ohSearchViewController animated:NO];
    return YES;
}


- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.ohSearchBar resignFirstResponder];
}

@end
